package com.kensure.mycom.em.service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import co.kensure.frame.JSBaseService;
import co.kensure.mem.CollectionUtils;
import co.kensure.mem.MapUtils;

import com.kensure.mycom.em.dao.EmployerDao;
import com.kensure.mycom.em.model.Employer;
import com.kensure.mycom.em.model.EmployerLogin;


/**
 * 员工服务实现类
 * @author fankd created on 2019-6-14
 * @since 
 */
@Service
public class EmployerService extends JSBaseService{
	
	@Resource
	private EmployerDao dao;
	@Resource
	private EmployerLoginService employerLoginService;
    
    
    public Employer selectOne(Long id){
    	return dao.selectOne(id);
    }
	
	public List<Employer> selectByIds(Collection<Long> ids){
		return dao.selectByIds(ids);
	}
	
	public List<Employer> selectAll(){
		return dao.selectAll();
	}
	
	public List<Employer> selectByWhere(Map<String, Object> parameters){
		return dao.selectByWhere(parameters);
	}
	
	
	public long selectCount(){
		return dao.selectCount();
	}
	
	public long selectCountByWhere(Map<String, Object> parameters){
		return dao.selectCountByWhere(parameters);
	}
	
	
	public boolean insert(Employer obj){
		return dao.insert(obj);
	}
	
	public boolean update(Employer obj){
		return dao.update(obj);
	}
    
    public boolean updateByMap(Map<String, Object> params){
		return dao.updateByMap(params);
	}
    
    
	public boolean delete(Long id){
		return dao.delete(id);
	}	
	
    public boolean deleteMulti(Collection<Long> ids){
		return dao.deleteMulti(ids);
	}
    
    public boolean deleteByWhere(Map<String, Object> parameters){
		return dao.deleteByWhere(parameters);
	}
    
    
    /**
	 * 根据登录号，用户
	 * 
	 * @param loginname
	 * @return
	 */
	public Employer selectByLoginame(String loginname) {
		Map<String, Object> parameters = MapUtils.genMap("loginname", loginname);
		List<Employer> userlist = selectByWhere(parameters);
		Employer u = null;
		if (CollectionUtils.isNotEmpty(userlist)) {
			u = userlist.get(0);
		}
		return u;
	}
	
	/**
	 * 通过spring的本地线程变量获取req,然后获取sessionid，获取变量,如果没有，返回null
	 */
	public Employer getUserByToken(String token) {
		EmployerLogin sKLogin = employerLoginService.selectByTokenId(token);
		if (sKLogin == null) {
			return null;
		}
		Employer user = selectOne(sKLogin.getUserid());
		return user;
	}
}
